package cn.aixuxi.notebank.controller;

import cn.aixuxi.notebank.authc.JwtToken;
import cn.aixuxi.notebank.constant.DefConstant;
import cn.aixuxi.notebank.dto.CategoryOutputDTO;
import cn.aixuxi.notebank.dto.NoteOutputDTO;
import cn.aixuxi.notebank.dto.TagOutputDTO;
import cn.aixuxi.notebank.dto.UserInputDTO;
import cn.aixuxi.notebank.entity.UserEntity;
import cn.aixuxi.notebank.service.CategoryService;
import cn.aixuxi.notebank.service.NoteService;
import cn.aixuxi.notebank.service.TagService;
import cn.aixuxi.notebank.util.JwtUtils;
import cn.aixuxi.notebank.util.RedisUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 类描述
 *
 * @author ruozhuliufeng
 * @version 1.0
 * @date 2020/10/24 20:43
 */
@Controller
public class IndexController {


    @Autowired
    RedisUtils redisUtils;
    @Autowired
    TagService tagService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    NoteService noteService;

    /**
     * 功能描述: 首页跳转
     * @return : java.lang.String
     * @author : ruozhuliufeng
     * @date : 2020/10/24 22:05
     */
    @RequestMapping({"/","/index"})
    public String index(HttpSession session){
        List<NoteOutputDTO> notelist = noteService.noteList();
        session.setAttribute("notelist",notelist);
        return "index";
    }

    /**
     * 功能描述: 登录页面跳转
     * @return : java.lang.String
     * @author : ruozhuliufeng
     * @date : 2020/10/24 22:05
     */
    @GetMapping("/login")
    public String login(){
        return "login";
    }

    @GetMapping("/list")
    public String list(){
        return "notes/noteList";
    }
    @GetMapping("/center")
    public String center(){
        return "user/center";
    }

    @GetMapping("/noteAdd")
    public String noteAdd(HttpSession session) {
        List<CategoryOutputDTO> categoryList = categoryService.findList();
        session.setAttribute("categoryList", categoryList);
        List<TagOutputDTO> tagList = tagService.tagList();
        session.setAttribute("tagList", tagList);
        return "notes/noteAdd";
    }

    @RequiresRoles("admin")
    @GetMapping("/admin")
    public String admin() {
        return "admin/main";
    }
}
